package com.tanhua.server.controller;

import com.tanhua.domain.db.User;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.server.interceptor.UserHolder;
import com.tanhua.server.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/users")
@Slf4j
public class UserInfoController {
    @Autowired
    private UserService userService;

    /**
     * 接口名称：用户资料 - 读取
     * 接口路径：GET/users
     * 需求描述：根据用户id查询用户详情
     */
    @GetMapping
    public ResponseEntity<Object> findUserInfoById() {
        log.info("接口名称：用户资料 - 读取");
        return userService.findUserInfoById();
    }

    /**
     * 接口名称：用户资料 - 保存
     * 接口路径：PUT/users
     */
    @PutMapping
    public ResponseEntity<Object> updateUserInfo(@RequestBody UserInfo userInfo) {
        log.info("接口名称：用户资料 - 保存");
        return userService.updateUserInfo(userInfo);
    }

    /**
     * 用户资料 - 保存头像, 更新用户头像
     * 接口路径：POST/users/header
     */
    @PostMapping("/header")
    public ResponseEntity<Object> updateUserHead(MultipartFile headPhoto) throws IOException {
        return userService.updateUserHead(headPhoto);
    }

}
